#include "../mtcp_module.h"


DPCK::DPCK()
{
	memset(&m_DPCK_REQ, 0, sizeof(m_DPCK_REQ));
}


DPCK::~DPCK()
{
}


int DPCK::I_IDLE_LOW(float v)
{
	m_DPCK_REQ.I_IDLE_LOW = v;
	return 0;
}
int DPCK::NVM_DATA(const char * data)	//1,2,3,4,5
{
	char * p = new char[strlen(data) + 1];
	strcpy(p, data);

	char * dd;
	char * k = strtok(p, ",");
	int index = 0;
	while (k)
	{
		printf("get : %s\r\n", k);
		m_DPCK_REQ.NVM_DATA[index++] = atof(k);
		if (index >=128) break;
		k = strtok(NULL, ",");
	}
	return 0;
}

int DPCK::setvalue(char *what, char* value)
{
	if (0 == strcmp(what, "I_IDLE_LOW")){
		I_IDLE_LOW(atof(value));
		return 0;
	}
	if (0 == strcmp(what, "NVM_DATA")){
		NVM_DATA(value);
		return 0;
	}

	return -1;
}

int DPCK::SendDPCK()
{
	int ret = SendFrame(kMTCP_CTRL_DPCK, &m_DPCK_REQ, sizeof(m_DPCK_REQ), nullptr, 0);
	tMTCP_payload_TEST_RSP rep;
	RecvResponse(&rep, sizeof(rep));
	return ret;
}